package cool.webstudy.admin.constant.enums.rescode.docker;

import cool.webstudy.admin.constant.enums.rescode.BaseResCodeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 莫振双
 * @date 2025/1/4 11:54
 * @description: 网络相关错误码
 */
@Slf4j
public enum NetworkResCodeEnum implements BaseResCodeEnum {
    RC_NETWORK_INFO_MISSING("90001", "网络信息参数缺失"),
    RC_ERROR_CREATE("90002", "网络创建失败，失败详情：{0}"),
    RC_ERROR_DELETE("90003", "网络删除失败，失败详情：{0}"),
    RC_ERROR_QUERY("90004", "网络查询失败，失败详情：{0}"),
    RC_ERROR_ASYNC_NETWORK_TO_DB("90005","同步网络配置至数据库失败！"),
    ;
    private String code;
    private String msg;

    NetworkResCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String msg() {
        return msg;
    }

    /**
     * 根据code获取msg静态方法，每个响应状态码枚举类都应有这个方法
     */
    public static NetworkResCodeEnum getMsgByCode(String code) {
        for (NetworkResCodeEnum networkResCodeEnum : NetworkResCodeEnum.values()) {
            if (networkResCodeEnum.code().equals(code)) {
                return networkResCodeEnum;
            }
        }
        log.error("getMsgByCode error:无法获取枚举值");
        return null;
    }
}
